<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\GiftService;
use Illuminate\Http\Request;

class GiftController extends Controller
{
    private $giftService;
    public function __construct(GiftService $giftService)
    {
        $this->giftService = $giftService;
    }
    public function giftList(Request $request)
    {
        $params = $request->input();
        $result = $this->giftService->giftList($params);
        return $this->responseSuccess($result);
    }


    public function giftAdd(Request $request)
    {
        $params = $request->input();
        if(isset($params['id']) && !empty($params['id'])){
            $result = $this->giftService->updateGift($params);
            if($result)
                return $this->responseSuccess($result);
            else
                return $this->responseError("更新失败，请重试！");
        }else{
            $result = $this->giftService->insertGift($params);
            if($result)
                return $this->responseSuccess($result);
            else
                return $this->responseError("新增失败，请重试！");
        }
    }

    public function giftDel(Request $request)
    {
        $params = $request->input();
        $result = $this->giftService->giftDel($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }

    public function giftRecord(Request $request)
    {
        $params = $request->input();
        $result = $this->giftService->giftRecord($params);
        return $this->responseSuccess($result);
    }

    public function giftRecordDel(Request $request)
    {
        $params = $request->input();
        $result = $this->giftService->giftRecordDel($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }
}
